import { createApp } from 'vue';
import tpl from './confirm.vue';
const isShowing = false;
/**
 * 使用方式
 * import {} from ''
 * hmdConfirm({
     com:import('@/dialog/tpl/commercialInformationQuery.vue'),
     style: {},//模板容器设置css
     params :{},//传给模板组件的参数
     paddingTop:20,//距离顶部的内边距，默认是上下居中
     lazy:false,//延时关闭，默认false
     duration:2,//默认2秒
     hideMask:false,//是否关闭遮罩层的背景色，默认false
     close:()=>{},//close回调
     cancel:()=>{},//取消回调
     confirm:()=>{}//确认回调
  });
 * @param options
 */
export const hmdConfirm = options => {
  /* fix 弹窗出来之后依旧键盘没有回收*/
  const inputs = Array.prototype.slice.call(document.querySelectorAll('input'));
  inputs.forEach(input => input.blur());
  const instance = createApp(tpl);
  instance.provide('config', options);
  const root = document.createElement('div');
  document.body.appendChild(root);
  instance.mount(root);
};
export default {
  install: app => {
    app.config.globalProperties.$hmdConfirm = hmdConfirm;
  },
};
